/**
 * @author xuyuhang
 */

var newer = newer || {};
newer.gd = newer.gd || {};

newer.PostDisplay = function(o) {
	this.domNode = o.domNode;
	
	this.idSuffix = (o.idSuffix!=undefined)?o.idSuffix:"";
	
	this.postInfo = o.postInfo;
	
	this.init();
};

newer.PostDisplay.prototype = {
	init: function() {
		this.domNode.html(	'<div class="post-display-container" id="post-display-container-'+this.idSuffix+'">'+
								'<div class="post-display-block1-div">'+
									'<img class="post-display-author-avatar-img" id="post-display-author-avatar-'+this.idSuffix+'" src="" width="50px"/>'+
								'</div>'+
								'<div class="post-display-block2-div">'+
									'<div class="post-display-author-name-div">'+this.postInfo.authorName+'</div>'+
									'<div class="post-display-date-div">'+this.postInfo.postDate+'</div>'+
									'<div class="post-display-content-div">'+this.postInfo.content+'</div>'+
								'</div>'+
							'</div>');
		// this.domNode.html("aaa");
		
		this.authorAvatarNode = $('#post-display-author-avatar-'+this.idSuffix);
		this.containerNode = $("#post-display-container-"+this.idSuffix);
		
		// bind mouse enter and leave effect
		//this.containerNode.on("mouseenter", $.proxy(this.mouseEnter, this));
		//this.containerNode.on("mouseleave", $.proxy(this.mouseLeave, this));
		
		this.refresh();
	},
	
	refresh: function() {
		if(this.postInfo.authorHasAvatar) {
			this.authorAvatarNode.attr("src","/Photos/displayUserPhoto?id="+this.postInfo.authorid+'&size=50&s='+Math.random()); 
		} else {
			this.authorAvatarNode.attr('src','/public/images/default-user-image');
		}	
	},
	
	mouseEnter: function() {
		this.containerNode.css({"background-color":"#def","border-color":"#cdf"});
	},
	
	mouseLeave: function() {
		this.containerNode.css({"background-color":"#fff","border-color":"#b2b2b2"});
	}
}

